package dal

import (
	"context"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	"mall_frontend_api/biz/config"
	"mall_frontend_api/biz/model"
)

func (c *ProductItemDAO) MGetByProductIDs(ctx context.Context, productIDs []int64) (map[int64][]*model.ProductItem, error) {
	list, err := ProductItem.WithContext(ctx).Where(
		ProductItem.BizID.Eq(config.Values.BizID),
		ProductItem.ProductID.In(productIDs...),
		ProductItem.DeletedAt.IsNull(),
	).Find()
	if err != nil {
		hlog.CtxErrorf(ctx, "dal.MGetProductItemByProductIDs err: %v", err)
		return nil, err
	}
	var data = make(map[int64][]*model.ProductItem)
	for _, info := range list {
		data[info.ProductID] = append(data[info.ProductID], info)
	}
	return data, nil
}
